package com.zpark.controller;

import com.zpark.pojo.TEmpty;
import com.zpark.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xiaoyu
 * @version 1.0 2022/9/13
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/find")
    public ModelAndView findAll() {
        //创建视图解析器
        ModelAndView mv = new ModelAndView();
        //设置视图名字
        mv.setViewName("each");
        // 调用业务层获取数据
        List<TEmpty> empties = userService.findAll();
        //绑定数据
        mv.addObject("lists", empties);
        return mv;

    }

    @RequestMapping("/empty")
    public ModelAndView getEmpty() {
        //创建视图解析器
        ModelAndView mv = new ModelAndView();
        //设置视图名字
        mv.setViewName("demo02");
        //创建 empty 对象
        TEmpty empty = new TEmpty(10, "张晓晓", "99999", "男", 9000.0, "西秀区");

        //绑定数据
        mv.addObject("empty", empty);
        return mv;

    }

    @RequestMapping("/map")
    public ModelAndView getMapEmpty() {
        //创建视图解析器
        ModelAndView mv = new ModelAndView();
        //设置视图名字
        mv.setViewName("map");
        //创建 empty 对象
        TEmpty empty = new TEmpty(10, "宵宫", "99999", "女", 1000000.0, "西秀区");

        //创建map 对象
        Map<String, Object> map = new HashMap<>();
        map.put("empty", empty);
        map.put("con", "hello thymeleaf");
        List<TEmpty> empties = userService.findAll();
        map.put("lists", empties);

        //绑定数据
        mv.addObject("maps", map);
        return mv;

    }



}
